1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import java.net.*;
35 import java.util.*;
36
37
38 public class Providers {
39 private static String[][] hostnames = new String[][] {
40
41 new String[] {"blade", "10.0.0.1"},
42
43 new String[] {"blade.domain1", "10.0.0.2"},
44
45 new String[] {"blade.domain2", "20.0.0.2"}
46 };
47 private static String[][] hostaddrs = new String[][] {
48 new String[] {"10.0.0.1", "blade"},
49 new String[] {"10.0.0.2", "blade.domain1"},
50 new String[] {"20.0.0.2", "blade.domain2"}
51 };
52
53 public static void main(String[] args) throws Exception {
54 for (int i = 0; i < hostnames.length; i++) {
55 doLookup(hostnames[i][0], hostnames[i][1]);
56 }
57 for (int i = 0; i < hostaddrs.length; i++) {
58 doReverseLookup(hostaddrs[i][0], hostaddrs[i][1]);
59 }
60 }
61
62 private static void doLookup(String host, String addr) throws Exception {
63 String res = InetAddress.getByName(host).getHostAddress();
64 if (!res.equals(addr)) {
65 throw new RuntimeException("Test failed: wrong address for host " + host);
66 }
67 }
68
69 private static void doReverseLookup(String addr, String host) throws Exception {
70 StringTokenizer tokenizer = new StringTokenizer(addr, ".");
71 byte addrs[] = new byte[4];
72 for (int i = 0; i < 4; i++) {
73 addrs[i] = (byte)Integer.parseInt(tokenizer.nextToken());
74 }
75 String res = InetAddress.getByAddress(addrs).getHostName();
76 if (!res.equals(host)) {
77 throw new RuntimeException("Test failed: wrong host name for address " + addr);
78 }
79 }
80 }